package cbs.demo;

import cbs.demo.mapper.PatientMapper;

import java.lang.reflect.Proxy;
import java.time.LocalDateTime;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) throws ClassNotFoundException {
        if (args.length <= 0) {
            return;
        }
        var clazz = Class.forName(args[0]);
        var instance = Proxy.newProxyInstance(
                Thread.currentThread().getContextClassLoader(),
                /*null,//native模式下这个参数可以是null
                 * */
                /*new Class[]{PatientMapper.class},*/
                new Class[]{clazz},
                (proxy, method, args1) -> {
                    //过滤掉object中的方法
                    if (Object.class.equals(method.getDeclaringClass())) {
//                    method.invoke()
                        return null;
                    }
                    System.out.println(LocalDateTime.now().toString());
                    System.out.println("方法:" + method.getName());
                    /**
                     * 执行sql
                     * 映射实体
                     * 返回实体
                     */
                    return null;
                });
        var id = Integer.parseInt(args[1]);
        if (instance instanceof PatientMapper) {
            ((PatientMapper) instance).getPatient(id);
        }
    }
}
